/*************************************************
* filename:     memcache_connection.h
* definition:   memcache db connection interface
* author:       liujianping@snda.com
*************************************************/

#ifndef EDM_MEMCACHE_CONNECTION_H
#define	EDM_MEMCACHE_CONNECTION_H



#include <string>
#include <vector>

extern "C"{
#include <libmemcached/memcached.h>
}

#include <string>
#include <vector>

namespace edm
{
    namespace network
    {
        #ifndef MYNET
        #define MYNET     "MYNET"
        #endif
        
        class memcache_connection_t
        {
        public:
            memcache_connection_t(const std::string& address,const std::string& port);
            ~memcache_connection_t();

            int connect();
            int close();
            int reconnect();

            int set(const std::string& key, const std::vector<char> &value,int store_expiration);
            int add(const std::string& key, const std::vector<char> &value,int store_expiration);
            int get(const std::string& key, std::vector<char> &ret_val);
            int del(const std::string& key);

            //! enum records begin
            int enum_init();
            //! result: -1: error 0: null key left 1: get a key
            int enum_next(std::string& ret_key); 
            
            bool connected()
            {
                return m_connected;
            }
        private:
            bool   m_connected;
            std::string m_address;
            std::string m_port;
            memcached_st m_memc;
            memcached_server_st *m_servers;
        };
    }
}

#endif	/* MEMCACHE_CONNECTION_H */

